// (c)2016 Flipboard Inc, All Rights Reserved.

package com.ysalliance.getFan.organization.ui.base;

import android.os.Bundle;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.ysalliance.getFan.organization.Bean.UserBean;
import com.ysalliance.getFan.organization.R;
import com.ysalliance.getFan.organization.myview.ProgressBarHandler;

import org.litepal.LitePal;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import io.reactivex.disposables.Disposable;

public abstract class LucasBaseFragment extends Fragment {

    /** 日志输出标志 **/
    protected final String TAG = this.getClass().getSimpleName();
    /** 上下文context **/
    public LucasBaseActivity mContext;
    /** RXjava释放 **/
    protected Disposable disposable;
    /** 用户 **/
    public UserBean userBean;
    /**    耗时缓冲bar   */
    public ProgressBarHandler mProgressBarHandler;
    /**   ButterKnife的绑定解绑器  */
    private Unbinder unbinder;
    /**   fragment的全局变量view   */
    public   View view;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mContext = (LucasBaseActivity) getActivity();
        if (null != view) {
            ViewGroup parent = (ViewGroup) view.getParent();
            if (null != parent) {
                parent.removeView(view);
            }
        } else {
            view = inflater.inflate(bindContentView(), container,false);
            unbinder = ButterKnife.bind(this, view);

            if(LitePal.findFirst(UserBean.class)!=null){
                userBean = LitePal.findFirst(UserBean.class);
            }

            /**   缓冲bar  .show()  .hide() */
            mProgressBarHandler = new ProgressBarHandler(mContext); // In onCreate
            afterview();
        }
        return view;
    }


    /**   绑定view  */
    public abstract int bindContentView();

    public abstract void afterview();

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unsubscribe();
//        unbinder.unbind();
    }


    protected void unsubscribe() {
        if (disposable != null && !disposable.isDisposed()) {
            disposable.dispose();
        }
    }


    @Override
    public void onResume() {
        super.onResume();


    }
}
